package com.vote.www.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.vote.www.utils.MapManage;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vote.www.core.page.Pagination;
import com.vote.www.domain.Czjbackground;
import com.vote.www.domain.Czjorder;
import com.vote.www.domain.vo.TorderVO;
import com.vote.www.persistence.CzjorderMapper;
import com.vote.www.utils.UUIDUtils;

/**
 * Created by 汤伟杰 on 2017/4/28.
 */
@Service
public class CzjorderService {

	@Autowired
	private CzjorderMapper czjorderMapper;

	public void insertCzjorder(Czjorder czjorder) throws Exception {
		if (StringUtils.isBlank(czjorder.getOrderId())) {
			czjorder.setOrderId(UUIDUtils.getDateUUID());
		}
		czjorderMapper.insertCzjorder(czjorder);
	}
	
	/**
	 * 查询czj_order  订单列表
	 * @return
	 */
	public  Pagination getCzjorderList(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=czjorderMapper.getTotalRows(param);
		List<Czjorder> list=	czjorderMapper.getCzjorderList(param);	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}
	
	/**
	 * 查询czj_order  订单列表
	 * @return
	 */
	public  Pagination getCzjorderListOther(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=czjorderMapper.getTotalRowsOther(param);
		List<Czjorder> list=	czjorderMapper.getCzjorderListOther(param);	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}
	
	/**
	 * 查询czj_order  订单列表
	 * @return
	 */
	public  TorderVO getOrderDetails(Map<String,Object> param) {	
		return  czjorderMapper.getOrderDetails(param);
	}	
	
	

	public Pagination getListCzjOrder(Map<String, Object> param) {
		List<Map<String,Object>> listmap = czjorderMapper.getListCzjOrder(param);
		List<Map<String,Object>> listmap1 = new ArrayList<Map<String,Object>>();
		
        for(Map<String, Object> map : listmap ){       	
        	if("7月深圳多彩跑".equals(map.get("remark"))){      		 
        		 map.put("bagOrAct", 1);
        	}else{
        		 map.put("bagOrAct", 2);
        	}
        	listmap1.add(map);
        }	
		MapManage.reservedForListMap(listmap1,"remark","ext2","ext3","imgPath","num","orderId","bagOrAct");
		Pagination pagination = new Pagination(0,10000,listmap1.size(),listmap1);
		return pagination;
	}
}
